
function [SpectraCell , Sigma_YRef , Sigma_Y] = Spectra(U , WRInt , WR , NRPF , Length)

N = length(U);
dist = codistributor1d(3);
dist1 = codistributor1d(1);

SpectraCell = cell(1 ,  N * ( N + 1 ) / 2 );
Sigma_YRef = cell(1 , N );
Sigma_Y = cell(1 , N );

c = 1;

for k = 1 : N
    u = U{k};
    
    u = codistributed( u , dist1 );
    FFT_Y_u = fft( u , Length , 2 );
    FFT_Y_u = gather(FFT_Y_u);
    
    FFT_YR_u = FFT_Y_u( WRInt(1) : WRInt(2) , : );
    FFT_YR_u = reshape(FFT_YR_u' , [1 , Length , WR ] );
    FFT_YR_u = repmat(FFT_YR_u , [NRPF , 1 , 1]);
    FFT_YR_u = codistributed(FFT_YR_u , dist);
    
    FFT_Y_u = repmat(FFT_Y_u , [1 , 1 , WR]);
    FFT_Y_u = codistributed(FFT_Y_u , dist);
    
    % Calculate RMS spectra at yr for normalization purposes.
    Sigma_YRef{k} = FFT_YR_u .* conj( FFT_YR_u );
    
    % Calculate RMS spectra at y for normalization purposes.
    Sigma_Y{k} = FFT_Y_u .* conj( FFT_Y_u );
    
    for m = k : N
        
        if m ~= k
            v = U{m};
            v = codistributed( v , dist1 );
            FFT_Y_v = fft( v , Length , 2 );
            FFT_Y_v = gather(FFT_Y_v);
            FFT_Y_v = repmat(FFT_Y_v , [1 , 1 , WR]);
            FFT_Y_v = codistributed(FFT_Y_v , dist);
        else
            FFT_Y_v = FFT_Y_u;
            
        end

        SpectraCell{c} = FFT_YR_u .* FFT_Y_v;
        c = c + 1;

    end
end


end